package com.ivan.ossservice.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.ivan.commonutils.CommonResult;
import com.ivan.ossservice.service.OssService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author Ivan
 * @Description 阿里云oss的controller
 * @Date 2020/8/7 23:06
 */
@Api("阿里云存储")
@RestController
@RequestMapping("/eduoss/fileoss")
@CrossOrigin
public class OssController {

    @Autowired
    private OssService ossService;

    /**
     * @Author Ivan
     * @Description 上传头像的方法
     * @Date 2020/8/7 23:13
     * @Param
     * @return
     */
    @ApiOperation(value = "上传头像的方法")
    @PostMapping
    public CommonResult uploadOssFile(MultipartFile file) {
        //获取上传文件  MultipartFile
        //返回上传到oss的路径
        String url = ossService.uploadFileAvatar(file);
        return CommonResult.success().data("url", url);
    }
}
